package com.dingwen.treasure.business.controller;

import com.dingwen.treasure.base.constant.ServerConstant;
import com.dingwen.treasure.base.controller.BaseViewController;
import com.dingwen.treasure.base.enums.OperateTypeEnum;
import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.business.model.dto.EasyCacheDto;
import com.dingwen.treasure.core.annotation.OperationLogRecord;
import com.dingwen.treasure.core.util.LogContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 　OperationLogRecordController: AOP 操作日志案例
 * 　@author dingwen
 * 　@date 2022/6/24
 */
@Api(tags = "AOP操作日志案例")
@RestController
@Slf4j
@RequestMapping("log")
public class OperationLogRecordController implements BaseViewController {

    /**
     * 测验简单参数
     *
     * @param id id
     * @return {@link Result}
     */
    @ApiOperation(value = "操作日志记录案例")
    @PostMapping("/{id}")
    @OperationLogRecord(
            methodKey = "test:id:easyCacheDTO",
            module = ServerConstant.TREASURE_BUSINESS,
            id = "#easyCacheDTO.id",
            operateType = OperateTypeEnum.OTHER,
            resourceName = "@ApiOperation",
            detail = true)
    public Result<Long> test(@PathVariable Long id, @RequestBody EasyCacheDto easyCacheDTO) {
        LogContext.set("test:id:easyCacheDTO", "test");
        return success(id);
    }
}
